#ifndef ResponseAttributeItem_H
#define ResponseAttributeItem_H

#include "TreeItem.h"
#include "..\core\src\AssetManager.h"
#include "..\core\src\container\ResponseAttribute.h"

namespace Xps
{
	class  ResponseAttributeItem : public TreeItem
	{
	public:
		
		ResponseAttributeItem(XpsAssets::AssetManager* am, int id, int pid = -1) : TreeItem(am,id,ModelItemType::RESPONSE_ATTRIBUTE, pid)
		{
			setIcon(QIcon(":/rs/images/attribute_ref.png"));
			asset = am->getResponse(pid)->attributes()->value(id);
		};
		
		QVariant ResponseAttributeItem::data(int role) const
		{
			XpsAssets::Attribute* a = NULL;
			XpsAssets::ResponseAttribute* ra = NULL;
			XpsAssets::Response* r = NULL;
					
			if (role == Qt::EditRole || role == Qt::DisplayRole)
			{
				a = am->getAttribute(id);
				r = am->getResponse(pid);
				ra = r->attributes()->value(id);

				if (ra == NULL)
					return a->name();

				return QString("%1 %2").arg(a->name()).arg(ra->value());
			}
				
			return TreeItem::data(role);
		}

		void ResponseAttributeItem::setData ( const QVariant & value, int role)
		{
			if (role != Qt::EditRole) 
				return TreeItem::setData(value,role);
		}
	};
}
#endif
